package com.mec.beans.y2012.coreservlet;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.apache.log4j.Logger;

public class ConnectionInfoBean {
	private String connectionName;
	private String description;
	private String driver;
	private String url;
	private String username;
	private String password;
	
	public static Connection getConnection(String driver, String url, String userName, String password){
		try{
			Class.forName(driver);
			//
			Connection connection = DriverManager.getConnection(url, userName, password);
			return connection;
		}catch(ClassNotFoundException cnfe){
			logger.error("Error loading driver: ", cnfe);
			return null;
		}catch(SQLException sqle){
			logger.error("Error connecting: ", sqle);
			return null;
		}
	}
	public ConnectionInfoBean(String connectionName, String description,
			String driver, String url, String userName, String password) {
		super();
		this.connectionName = connectionName;
		this.description = description;
		this.driver = driver;
		this.url = url;
		this.username = userName;
		this.password = password;
	}
	public String getConnectionName() {
		return connectionName;
	}
	public void setConnectionName(String connectionName) {
		this.connectionName = connectionName;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getDriver() {
		return driver;
	}
	public void setDriver(String driver) {
		this.driver = driver;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String userName) {
		this.username = userName;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	private static final Logger logger = 
			Logger.getLogger(ConnectionInfoBean.class);

}
